﻿// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.Sarif.Processors
{
    public class SarifLogActionTuple
    {
        public SarifLogAction Action;
        public string[] Parameters;

        /// <summary>
        /// Two ActionTuples are equal if they take the same actions with the same parameters.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is SarifLogActionTuple other))
            {
                return base.Equals(obj);
            }

            if (this.Action != other.Action)
            {
                return false;
            }

            if (this.Parameters != null && other.Parameters != null)
            {
                if (this.Parameters == null || other.Parameters == null)
                {
                    return false;
                }

                if (this.Parameters.Length != other.Parameters.Length)
                {
                    return false;
                }

                for (int i = 0; i < this.Parameters.Length; i++)
                {
                    if (!this.Parameters[i].Equals(other.Parameters[i]))
                    {
                        return false;
                    }
                }
            }

            return true;
        }

        /// <summary>
        /// Generated by Visual Studio--we're overriding Equals() so we need to override this as well.
        /// </summary>
        public override int GetHashCode()
        {
            int hashCode = -2011433744;
            hashCode = hashCode * -1521134295 + Action.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer<string[]>.Default.GetHashCode(Parameters);
            return hashCode;
        }
    }
}
